home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / mpeg / other.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  139 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "video.h"
  4. #include "proto.h"
  5.  
  6. extern FILE *input;
  7. extern int EOF_flag, seek_only;
  8.  
  9. /*
  10.  *--------------------------------------------------------------
  11.  *
  12.  * DoDitherImage --
  13.  *
  14.  *    Called when image needs to be dithered. Selects correct
  15.  *      dither routine based on info in ditherType.
  16.  *
  17.  * Results:
  18.  *    None.
  19.  *
  20.  * Side effects:
  21.  *    None.
  22.  *
  23.  *--------------------------------------------------------------
  24.  */
  25.  
  26. void
  27. DoDitherImage(l, Cr, Cb, disp, h, w)
  28.      unsigned char *l, *Cr, *Cb, *disp;
  29.      int h, w;
  30. {
  31.     if (!seek_only)
  32.     ColorDitherImage(l, Cr, Cb, disp, h, w);
  33. }
  34.  
  35. /*
  36.  *--------------------------------------------------------------
  37.  *
  38.  * get_more_data --
  39.  *
  40.  *    Called by correct_underflow in bit parsing utilities to
  41.  *      read in more data.
  42.  *
  43.  * Results:
  44.  *    Input buffer updated, buffer length updated.
  45.  *      Returns 1 if data read, 0 if EOF, -1 if error.
  46.  *
  47.  * Side effects:
  48.  *      None.
  49.  *
  50.  *--------------------------------------------------------------
  51.  */
  52. int
  53. get_more_data(buf_start, max_length, length_ptr, buf_ptr)
  54.      unsigned int *buf_start;
  55.      int max_length;
  56.      int *length_ptr;
  57.      unsigned int **buf_ptr;
  58. {
  59.  
  60.     int length, num_read, i, request;
  61.     unsigned char *buffer, *mark;
  62.     unsigned int *lmark;
  63.  
  64.     if (EOF_flag)
  65.     return 0;
  66.  
  67.     length = *length_ptr;
  68.     buffer = (unsigned char *) *buf_ptr;
  69.  
  70.     if (length > 0)
  71.       {
  72.       memcpy((unsigned char *) buf_start, buffer, (length * 4));
  73.       mark = ((unsigned char *) (buf_start + length));
  74.       }
  75.     else
  76.       {
  77.       mark = (unsigned char *) buf_start;
  78.       length = 0;
  79.       }
  80.  
  81.     request = (max_length - length) * 4;
  82.  
  83.     num_read = fread(mark, 1, request, input);
  84.  
  85.     /* Paulo Villegas - 26/1/1993: Correction for 4-byte alignment */
  86.     {
  87.     int num_read_rounded;
  88.     unsigned char *index;
  89.  
  90.     num_read_rounded = 4 * (num_read / 4);
  91.  
  92.     /* this can happen only if num_read<request; i.e. end of file reached */
  93.     if (num_read_rounded < num_read)
  94.       {
  95.           num_read_rounded = 4 * (num_read / 4 + 1);
  96.           /* fill in with zeros */
  97.           for (index = mark + num_read; index < mark + num_read_rounded; *(index++) = 0) ;
  98.           /* advance to the next 4-byte boundary */
  99.           num_read = num_read_rounded;
  100.       }
  101.     }
  102.  
  103.     if (num_read < 0)
  104.       {
  105.       return -1;
  106.       }
  107.     else if (num_read == 0)
  108.       {
  109.       *buf_ptr = buf_start;
  110.  
  111.       /*
  112.        * Make 32 bits after end equal to 0 and 32 bits after that equal
  113.        * to seq end code in order to prevent messy data from infinite
  114.        * recursion.
  115.        */
  116.  
  117.       *(buf_start + length) = 0x0;
  118.       *(buf_start + length + 1) = SEQ_END_CODE;
  119.  
  120.       EOF_flag = 1;
  121.       return 0;
  122.       }
  123.  
  124.     lmark = (unsigned int *) mark;
  125.  
  126.     num_read = num_read / 4;
  127.  
  128.     for (i = 0; i < num_read; i++)
  129.       {
  130.       *lmark = htonl(*lmark);
  131.       lmark++;
  132.       }
  133.  
  134.     *buf_ptr = buf_start;
  135.     *length_ptr = length + num_read;
  136.  
  137.     return 1;
  138. }
  139.